﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Net.Mail;

namespace HistoryToMail
{

    

    public partial class SMTPSettingsForm : Form
    {
        private SmtpClient smtp = new SmtpClient();
        private SMTPSettings settings;

        public SMTPSettingsForm(SMTPSettings settings)
        {
            InitializeComponent();
            this.settings = settings;
            loadSettings();
        }

        private void loadSettings()
        {
            serverAddress.Text = settings.serverAddress;
            serverPort.Value = settings.serverPort;
            enableSSL.Checked = settings.serverUseSSL;
            serverAuth.Checked = settings.serverUseAuth;
            userName.Text = settings.serverUserName;
            serverPassword.Text = settings.serverPassword;
            senderAddress.Text = settings.senderAddress;
            replyAddress.Text = settings.replyAddress;
            destinationAddress.Text = settings.destinationAddress;
        }

        private void saveSettings()
        {
            settings.serverAddress = serverAddress.Text;
            settings.serverPort = (int) serverPort.Value;
            settings.serverUseSSL = enableSSL.Checked;
            settings.serverUseAuth = serverAuth.Checked;
            settings.serverUserName = userName.Text;
            settings.serverPassword = serverPassword.Text;
            settings.senderAddress = senderAddress.Text;
            settings.replyAddress = replyAddress.Text;
            settings.destinationAddress = destinationAddress.Text;
        }


        private void saveButton_Click(object sender, EventArgs e)
        {
            saveSettings();
            Close();
            /*try
            {
                MailMessage message = new MailMessage(senderAddress.Text, destinationAddress.Text, "Test e-mail", "Test body");
                System.Net.NetworkCredential SMTPUserInfo = new System.Net.NetworkCredential(userName.Text, serverPassword.Text);
                smtp.Host = serverAddress.Text;
                smtp.EnableSsl = enableSSL.Checked;
                smtp.Port = (int)serverPort.Value;
                smtp.UseDefaultCredentials = false;
                smtp.Credentials = SMTPUserInfo;
                smtp.Send(message);
            }
            catch (Exception exception)
            {
            }*/
        }

        private void cancelButton_Click(object sender, EventArgs e)
        {
            Close();
        }


    }
}
